package com.my.event.listener;

import com.my.h2.logs.LogError;
import com.my.event.domin.ErrorLogEvent;
import com.my.h2.logs.LogErrorH2Dao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

import java.util.Map;

/**
 * @author timo 2021/2/25
 */
public class ErrorLogListener {
    private static final Logger log = LoggerFactory.getLogger(ErrorLogListener.class);
//    private final ILogClient logService;
//    private final ServerInfo serverInfo;
//    private final BladeProperties bladeProperties;
    private LogErrorH2Dao logErrorH2Dao;
    @Async
    @Order
    @EventListener({ErrorLogEvent.class})
    public void saveErrorLog(ErrorLogEvent event) {
        Map<String, Object> source = (Map)event.getSource();
        LogError logError = (LogError)source.get("log");
//        log.info("log==saveErrorLog==="+logError.toString());
//        LogAbstractUtil.addOtherInfoToLog(logError, this.bladeProperties, this.serverInfo);
        this.logErrorH2Dao.save(logError);
    }
    public ErrorLogListener(LogErrorH2Dao logErrorH2Dao){
        this.logErrorH2Dao = logErrorH2Dao;
    }
//    public ErrorLogListener(final ILogClient logService, final ServerInfo serverInfo, final BladeProperties bladeProperties) {
//        this.logService = logService;
//        this.serverInfo = serverInfo;
//        this.bladeProperties = bladeProperties;
//    }
}
